﻿#pragma once

#include <QWidget>

// 是改变图形内部的颜色还是线的颜色
enum class SvgColorTarget
{
	Inner,
	Line
};

class SvgPalette : public QWidget
{
	Q_OBJECT
public:
	explicit SvgPalette(QWidget *parent);

public slots:
	void ChangeColor(const QColor &inner, const QColor &line);

signals:
	void ColorChanged(QColor color, SvgColorTarget target);

protected:
	void paintEvent(QPaintEvent *event) override;
	void mousePressEvent(QMouseEvent *event) override;

private:
	static void _PaintColorPicker(QPainter &painter);
	void _PaintTargetBlock(QPainter &painter) const;
	void _PaintLineBlock(QPainter &painter) const;
	void _PaintInnerBlock(QPainter &painter) const;
	QColor &_GetTargetColor();

	static QColor _GetColorByPos(const QPointF &p);
	static QColor _GetColorByIndex(int x, int y);

private:
	SvgColorTarget m_target = SvgColorTarget::Inner;
	QColor m_innerColor = QColor(0xff, 0xff, 0xff, 0);
	QColor m_lineColor = QColor(0, 0, 0);
};